﻿var ge;

// Constructor
google.load("earth", "1");

function init()
{
google.earth.createInstance('map3d', initCB, failureCB);
}

// CB stands for CallBack
function initCB(instance)
{
ge = instance;
ge.getWindow().setVisibility(true);
}

function failureCB(errorCode)
{
}

function SetCoordinates(latitude, longitude, altitude)
{
// Get the current view
var lookAt = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);

// Set new latitude and longitude values
lookAt.setLatitude(latitude);
lookAt.setLongitude(longitude);
lookAt.setAltitude(2);

// Update the view in Google Earth
//ge.getView().setAbstractView(lookAt);

// Get the current view
var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);

// Zoom out to twice the current distance
camera.setAltitude(100);
camera.setLatitude(latitude);
camera.setLongitude(longitude);

// Update the view in Google Earth
ge.getView().setAbstractView(camera);
}

google.setOnLoadCallback(init);